<?php
	require_once ("function.php");
	// if the 'term' variable is not sent with the request, exit
if ( !isset($_REQUEST['zip']) )
	exit;
 
$conn= GetConnection();
 
// query the database table for zip codes that match 'term'
$rs = mysql_query('SELECT zip, city, state from US_Zip_Codes where zip like "'. mysql_real_escape_string($_REQUEST['zip']) .'%" order by zip asc limit 0,10', $conn);
 
// loop through each zipcode returned and format the response for jQuery
$data = array();
if ( $rs && mysql_num_rows($rs) )
{
	while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
	{
		$data[] = array(
			'label' => $row['zip'] .', '. $row['city'] .' '. $row['state'] ,
			'value' => $row['zip']
		);
	}
}
 
// jQuery wants JSON data
echo json_encode($data);
flush();
?>